<html>
<head><meta charset="utf-8"><title>Inner crate attributes · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Inner.20crate.20attributes.html">Inner crate attributes</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195284738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Inner%20crate%20attributes/near/195284738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Inner.20crate.20attributes.html#195284738">(Apr 25 2020 at 13:22)</a>:</h4>
<p>Hi! I'm trying to query whether there's a <code>#![no_std]</code> attribute on the crate, but for some reason <code>db.attrs</code> always returns an empty attribute list. Are crate-level attributes not recorded?</p>



<a name="195284770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Inner%20crate%20attributes/near/195284770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Inner.20crate.20attributes.html#195284770">(Apr 25 2020 at 13:23)</a>:</h4>
<p>Probably just a bug with handling of inner attributes</p>



<a name="195284954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Inner%20crate%20attributes/near/195284954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Inner.20crate.20attributes.html#195284954">(Apr 25 2020 at 13:28)</a>:</h4>
<div class="codehilite"><pre><span></span>    pub(crate) fn attrs_query(db: &amp;dyn DefDatabase, def: AttrDefId) -&gt; Attrs {
        match def {
            AttrDefId::ModuleId(module) =&gt; {
                let def_map = db.crate_def_map(module.krate);
                let src = match def_map[module.local_id].declaration_source(db) {
                    Some(it) =&gt; it,
                    None =&gt; return Attrs::default(),
                };
                Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &amp;dyn AttrsOwner))
            }
</pre></div>



<a name="195284968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Inner%20crate%20attributes/near/195284968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Inner.20crate.20attributes.html#195284968">(Apr 25 2020 at 13:29)</a>:</h4>
<p>Yup, so here we only look at <code>declaration_source</code> (the <code>mod foo;</code>), we don't look at the <code>definition_source</code></p>



<a name="195284972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Inner%20crate%20attributes/near/195284972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Inner.20crate.20attributes.html#195284972">(Apr 25 2020 at 13:29)</a>:</h4>
<p>For crate root module (and only for crate root module) the <code>declaration_source</code> is <code>None</code>.</p>



<a name="195285018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Inner%20crate%20attributes/near/195285018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Inner.20crate.20attributes.html#195285018">(Apr 25 2020 at 13:30)</a>:</h4>
<p>That is, we hit the <code>return Attrs::defualt</code> branch</p>



<a name="195286954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Inner%20crate%20attributes/near/195286954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Inner.20crate.20attributes.html#195286954">(Apr 25 2020 at 14:22)</a>:</h4>
<p>Oh awesome, that helps!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>